<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>操作日志</el-breadcrumb-item>
    </el-breadcrumb>

    <div style="margin-top: 20px">
      <div class="form">
        <el-form :inline="true" :model="ruleForm1" ref="ruleForm" >
          <el-form-item label="模块名:">
            <el-input v-model="ruleForm1.title" placeholder="请输入模块名"></el-input>
          </el-form-item>
          <el-form-item label="操作位置:">
            <el-input v-model="ruleForm1.type" placeholder="请输入操作位置"></el-input>
          </el-form-item>
          <el-form-item label="状态:">
            <el-select v-model="ruleForm1.status" placeholder="请选择状态">
              <el-option label="请选择" value="-1"></el-option>
              <el-option label="成功" value="0"></el-option>
              <el-option label="失败" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="search('ruleForm')">搜索</el-button>
            <el-button type="primary" @click="clean()">清空日志</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :data="tableData"
          style="width: 100%">
          <el-table-column
            prop="operId"
            label="序号"
            width="80">
          </el-table-column>
          <el-table-column
            prop="title"
            label="操作模块"
            width="180">
          </el-table-column>
          <el-table-column
            prop="method"
            label="操作方法"
            width="120">
          </el-table-column>
          <el-table-column
            prop="operUrl"
            label="操作地址"
            width="90">
          </el-table-column>
          <el-table-column
            prop="operIp"
            label="主机地址"
            width="180">
          </el-table-column>
          <el-table-column
            prop="operLocation"
            label="操作位置"
            width="120">
          </el-table-column>
          <el-table-column
            prop="operTime"
            label="操作时间"
            width="180">
          </el-table-column>
          <el-table-column
            prop="jsonResult"
            label="返回结果"
            width="180"
            :show-overflow-tooltip="show">
          </el-table-column>
          <el-table-column
            prop="costTime"
            label="消耗时间(ms)"
            width="120">
          </el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            width="80">
            <template slot-scope="scope">
              <span v-if="scope.row.status == 0">成功</span>
              <span v-else-if="scope.row.status == 1">失败</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="pagination.currentPage"
        :page-size="pagination.pageSize"
        layout="total , prev, pager, next, jumper"
        :total="pagination.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getLog} from "@/api/opction.js"
import {cleanLog} from "../../../api/opction";
export default {
  name: "index.vue",
  data(){
    return {
      tableData:{},
      ruleForm1:{},
      pagination: {//分页相关模型数据
        currentPage: 1,//当前页码
        pageSize: 10,//每页显示的记录数
        total: 0//总记录数
      },
      show:true
    }
  },
  created() {
    this.getList(this.pagination.currentPage,this.pagination.pageSize)
  },
  methods:{

    getList(pageNumber,pageSize){
      getLog(pageNumber,pageSize).then(result => {
        console.log(result)
        this.tableData=result.data.records
        this.pagination.pageSize = result.data.size;
        this.pagination.total = result.data.total
      })
    },
    search(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
          getLog(this.pagination.currentPage, this.pagination.pageSize, this.ruleForm1).then(result => {
            this.tableData = result.data.records
            this.pagination.pageSize = result.data.size;
            this.pagination.total = result.data.total
          })
        }else {
          this.$message.error("数据校验失败")
          return false;
        }
      })
    },
    clean(){
      cleanLog().then(result => {
        if(result.code==200){
          this.getList(this.pagination.currentPage,this.pagination.pageSize)
        }
      })
    },
    handleCurrentChange(currentPage){
      this.getList(currentPage,this.pagination.pageSize,this.ruleForm1)
    }

  }
}
</script>

<style scoped>

</style>
